document.addEventListener('DOMContentLoaded', function () {
    let projects = document.getElementsByClassName('project');
    let judges = document.getElementsByClassName('judge');
    let qs=document.getElementsByClassName('q');
    let lis=document.querySelector('.slideBar').children;
    const arry=[];
    // console.log(qs);
    for (let i = 0; i < projects.length; i++) {
        // console.log(projects[i].children[1].innerHTML);
        let num = i + 1;
        // i 题目的索引号
        let j_2 = judges[i].querySelectorAll('div');
        // 此处的conlus为某一个judge的兄弟元素
        let conlus = judges[i].nextElementSibling;
        let nextBtns = conlus.nextElementSibling;
        // console.log(conlus);
        projects[i].children[1].innerHTML = '(' + num + ')\t' + projects[i].children[1].innerHTML;

        // 点击选项显示对应结论，跳转按钮
        for (let j = 0; j < j_2.length; j++) {
            j_2[j].addEventListener('click', function () {
                // 获取点击的A或B
                // console.log(j);
                let ans_2 = conlus.querySelectorAll('p');
                let choice_2 = nextBtns.querySelectorAll('a');
                for (let i = 0; i < ans_2.length; i++) {
                    ans_2[i].style.display = 'none';
                    j_2[i].classList.remove('jClicked');
                    choice_2[i].style.display = 'none';
                }
                ans_2[j].style.display = 'block';
                j_2[j].classList.add('jClicked');
                choice_2[j].style.display = 'block';
            }
            )
        }
        // 思路1：（死板舍弃）
        // 获取所有跳转小a 共30,
        // 判断条件：
        // 1.点击a显示---页面 题目i+1
        // 2.如果满足a的索引号t等于
        // t1--2， 跳转到题目--3（第四题）
        // t2--4，跳转到题目---3（第四题）
        // 7--14，跳转到题目---8（第九题）

        // 思路2：（结构语义更强）
        // 判断条件添加点击事件：
        // 如果i=0,1;{
        //     nextBtns的[0]题目页面跳转到i=i+1,[1]跳转到i=3
        // }
        // 如果i=6{
        //     nextBtns的[0]题目页面跳转到i=i+1,[1]跳转到i=8
        // }
        // 跳转通过添加移除类名实现
        if(i==0||i==1){
            nextBtns.children[0].addEventListener('click',function(){
                arry.push(conlus.children[1].innerText);
                console.log(conlus.children[1].innerText);
                console.log(arry);
                // 排他
                for (let i = 0; i < qs.length; i++) {
                    qs[i].classList.remove('nowQuestion');
                    lis[i].classList.remove('dotted');
                }
                qs[i+1].classList.add('nowQuestion');
                lis[i+1].classList.add('dotted');
            })
            nextBtns.children[1].addEventListener('click',function(){
                arry.push(conlus.children[2].innerText);
                console.log(conlus.children[2].innerText);
                console.log(arry);
                // 排他
                for (let i = 0; i < qs.length; i++) {
                    qs[i].classList.remove('nowQuestion');
                    lis[i].classList.remove('dotted');
                }
                qs[3].classList.add('nowQuestion');
                lis[3].classList.add('dotted');
            })
            }
        else if(i==6){
            nextBtns.children[0].addEventListener('click',function(){
                arry.push(conlus.children[1].innerText);
                console.log(conlus.children[1].innerText);
                console.log(arry);
                // 排他
                for (let i = 0; i < qs.length; i++) {
                    qs[i].classList.remove('nowQuestion');
                    lis[i].classList.remove('dotted');
                }
                qs[i+1].classList.add('nowQuestion');
                lis[i+1].classList.add('dotted');
            })
            nextBtns.children[1].addEventListener('click',function(){
            arry.push(conlus.children[2].innerText);
                console.log(conlus.children[2].innerText);
                console.log(arry);
                // 排他
            for (let i = 0; i < qs.length; i++) {
                qs[i].classList.remove('nowQuestion');
                lis[i].classList.remove('dotted');
            }
            qs[8].classList.add('nowQuestion');
            lis[8].classList.add('dotted');
            })
        }
        else if(i==14){
            nextBtns.children[0].addEventListener('click',function(){
                arry.push(conlus.children[1].innerText);
                console.log(conlus.children[1].innerText);
                // 关闭浏览器窗口为生命周期存储数据
                for(var i=0 ;i<arry.length;i++){
                    sessionStorage.setItem(i,arry[i]);
                    console.log(i);
                }
                console.log(arry);
                location.href='../html/conlusion.html';
            })
            nextBtns.children[1].addEventListener('click',function(){
                arry.push(conlus.children[2].innerText);
                console.log(conlus.children[2].innerText);
                console.log(arry);
                // 关闭浏览器窗口为生命周期存储数据
                for(var i=0 ;i<arry.length;i++){
                    sessionStorage.setItem(i,arry[i]);
                    console.log(i);
                }
                location.href='../html/conlusion.html';
            })
        }
        else{
            nextBtns.children[0].addEventListener('click',function(){
                arry.push(conlus.children[1].innerText);
                console.log(conlus.children[1].innerText);
                console.log(arry);
                // 排他
                for (let i = 0; i < qs.length; i++) {
                    qs[i].classList.remove('nowQuestion');
                    lis[i].classList.remove('dotted');
                }
                qs[i+1].classList.add('nowQuestion');
                lis[i+1].classList.add('dotted');
            })
            nextBtns.children[1].addEventListener('click',function(){
                arry.push(conlus.children[2].innerText);
                console.log(conlus.children[2].innerText);
                console.log(arry);
                // 排他
                for (let i = 0; i < qs.length; i++) {
                    qs[i].classList.remove('nowQuestion');
                    lis[i].classList.remove('dotted');
                }
                qs[i+1].classList.add('nowQuestion');
                lis[i+1].classList.add('dotted');
            })
        }
    }
    // 获取judge[i]的两个div孩子的索引;
})
